home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / kgdb-4.5 / ds3100.md / gdb / kgdbcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-22  |  3.9 KB  |  181 lines

  1. /* Commands special for KGDB.
  2. ding!
  3. */
  4.  
  5. #include "defs.h"
  6. #include "symtab.h"
  7. /*#include "param.h"*/
  8. #include "frame.h"
  9. #include "inferior.h"
  10. #include "environ.h"
  11. #include "value.h"
  12. #include "target.h"
  13.  
  14. #include <stdio.h>
  15. #include <signal.h>
  16.  
  17. extern int remote_debugging;
  18.  
  19. void
  20. attach_command (args, from_tty)
  21.      char *args;
  22.      int from_tty;
  23. {
  24.   char *exec_file;
  25.   int pid;
  26.   int remote = 0;
  27.  
  28.   dont_repeat();
  29.  
  30.   if (!args)
  31.     error_no_arg ("hostname to attach");
  32.  
  33.   while (*args == ' ' || *args == '\t') args++;
  34.  
  35.  
  36.   exec_file = (char *) get_exec_file (1);
  37.  
  38.  
  39.   printf ("Attaching remote machine %s\n",args);
  40.   remote_open (args, from_tty);
  41. /* This is already done in remote_open. */
  42. /*  start_remote ();                    */
  43. }
  44.  
  45.  
  46. static void
  47. detach_command (args, from_tty)
  48.      char *args;
  49.      int from_tty;
  50. {
  51.  
  52.   if (!inferior_pid)
  53.     error ("Not currently debugging a machine\n");
  54.   if (from_tty) {
  55.       if (args) 
  56.       printf ("Detaching with execution restarted.\n");
  57.       else
  58.       printf ("Detaching.\n");
  59.       fflush (stdout);
  60.     }
  61.   remote_detach(args, from_tty);
  62.   inferior_pid = 0;
  63. }
  64.  
  65.  
  66. /* remote the remote machine. */
  67. void
  68. reboot_command (args, from_tty)
  69.      char *args;
  70.      int from_tty;
  71. {
  72.   dont_repeat();
  73.   if (!remote_debugging || !inferior_pid) {
  74.     error ("Not currently debugging a machine\n");
  75.   }    
  76.   remote_reboot(args);
  77. }
  78. static void
  79. pid_command (args, from_tty)
  80.      char *args;
  81.      int from_tty;
  82. {
  83.   int    pid;
  84.  
  85.   if (!args)
  86.     error_no_arg ("Must specifiy a process id");
  87.  
  88.   pid = value_as_long (evaluate_expression (parse_expression (args)));
  89.   if (from_tty) {
  90.       printf ("Attaching process entry: 0x%x\n", pid);
  91.   }
  92.   target_attach(pid, from_tty);
  93. }
  94.  
  95. static void
  96. version_command (args, from_tty)
  97.      char *args;
  98.      int from_tty;
  99. {
  100. /* Not implemented yet.
  101.   char    *version, *remote_version();
  102.   version = remote_version();
  103.   if (from_tty && version) 
  104.      printf("%s\n",version);
  105. */
  106. }
  107.  
  108. static void
  109. debug_command (args, from_tty)
  110.      char *args;
  111.      int from_tty;
  112. {
  113.   int result;
  114.   char *dbgString;
  115.   if (!args)
  116.     error_no_arg ("hostname");
  117.   dbgString = (char *)xmalloc(8+strlen(args));
  118.   sprintf(dbgString, "kmsg -d %s", args);
  119.   result = system(dbgString);
  120.   if (result == 0)
  121.       attach_command(args,from_tty);
  122. }
  123.  
  124. /* Set the start of the text segment  */
  125. static void
  126. text_command (args, from_tty)
  127.      char *args;
  128.      int from_tty;
  129. {
  130.   char *exec_file;
  131.   extern CORE_ADDR text_start;
  132.   extern CORE_ADDR text_end;
  133.   extern CORE_ADDR exec_data_start;
  134.   extern CORE_ADDR exec_data_end;
  135.   CORE_ADDR new_start;
  136.  
  137.  
  138.   dont_repeat();
  139.  
  140.   if (!args)
  141.     error_no_arg ("Text start address");
  142.  
  143.   while (*args == ' ' || *args == '\t') args++;
  144.  
  145.   new_start = value_as_long (evaluate_expression (parse_expression (args)));
  146.  
  147.  
  148.   exec_file = (char *) get_exec_file (1); /* Make sure we have an exec file */
  149.  
  150.  
  151.   text_end =  (text_end - text_start) + new_start;
  152.   text_start = new_start;
  153.   exec_data_end =  (exec_data_end - exec_data_start) + text_end;
  154.   exec_data_start =  text_end;
  155.  
  156. }
  157.  
  158.  
  159. _initialize_kgdbcmd ()
  160. {
  161.   add_com ("reboot", class_obscure, reboot_command,
  162.        "Reboot the machine being debugged.");
  163.   add_com ("pid", class_obscure, pid_command, 
  164.        "Set the process id to be debugged.");
  165.   add_com ("version", class_obscure, version_command, 
  166.        "Print the version string of the kernel being debugged.");
  167.   add_com ("debug", class_obscure, debug_command, 
  168.        "Force the specified host into the debugger and attach it.");
  169.   add_com ("text", class_obscure, text_command, 
  170.        "Specify the starting address of the text segment.");
  171.  add_com ("attach", class_run, attach_command,
  172.        "Attach to a machine in to debugger.\n\
  173. Before using \"attach\", you must use the \"exec-file\" command\n\
  174. to specify the program running in the process,\n\
  175. and the \"symbol-file\" command to load its symbol table.");
  176.   add_com ("detach", class_run, detach_command,
  177.        "Detach the machine previously attached.\n\
  178. If a non zero argument is specified, the machine execution is not resumed.");
  179. }
  180.  
  181.